import { useEffect, useState } from 'react'

// http://geek.itheima.net/v1_0/channels
// const URL = 'http://geek.itheima.net/v1_0/channels'


function Son() {
  useEffect(() => {
    const timer = setInterval(() => {
      console.log('定时器执行了')
    }, 1000)
    return () => {
      console.log('useEffect清除副作用')
      clearInterval(timer)
    }
  }, [])

  return (
    <div>This is son</div>
  )
}

function App() {
  const [show, setShow] = useState(true)

  return (
    <div>
      <h1>This is APP :useEffect清除副作用</h1>
      {/**当show为true时显示Son组件 */}
      {show && <Son />}
      <button onClick={() => setShow(false)}>卸载Son组件</button>
    </div>
  )
}

export default App;